package jjn.round1;

import java.util.HashSet;
import java.util.Set;

/**
 * @author Jjn
 * @since 2022/8/23 00:13
 */
public class LeetCode3_LengthOfLongestSubstring {

    public int lengthOfLongestSubstring(String s) {
        if (s == null || s.length() == 0) {
            return 0;
        }
        int left = 0, right;
        int max = s.length();
        int longest = 0;
        while (left < max) {
            Set<Character> set = new HashSet<>();
            right = left;
            while (right < max && !set.contains(s.charAt(right))) {
                set.add(s.charAt(right));
                right++;
            }
            longest = Math.max(longest, right - left);
            left++;
        }
        return longest;
    }
}
